#
# @lc app=leetcode.cn id=151 lang=python3
#
# [151] 翻转字符串里的单词
#


# @lc code=start
class Solution:
    def reverseWords(self, s: str) -> str:
        q = []
        word = []
        left = 0
        n = len(s)
        while left < n:
            if s[left] != " ":
                word.append(s[left])
            elif word:
                q.insert(0, "".join(word))
                word.clear()
            left += 1
        if word:
            q.insert(0, "".join(word))
        return " ".join(q)


# @lc code=end
